package example.string;

import java.sql.Time;

/**
 * Created by lenovo on 2016/11/4 0004.
 * 两种方式创建字符串，并测试其性能
 */
public class StringPerformance {
    public static void main(String[] args){
        long startTime = System.nanoTime();//起始时间
        for(int i = 0;i<50000;i++){
            String s1 = "hello";
            String s2 = "world";
        }
        long endTime = System.nanoTime();
        System.out.println("String = \"\" 创建字符串 时间：" + (endTime-startTime));
        long start = System.nanoTime();
        for (int i = 0;i<50000;i++){
            String str = new String("hello");
            String string = new String("world");
        }
        long end = System.nanoTime();
        System.out.println("String = new String() 创建字符串 时间：" + (end-start));
    }
}
